<?php

/**
 * This file is part of the Pagizer package.
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * @copyright   Copyright (c) 2010 Advisa (http://www.advisa.fr)
 * @author      Pagizer Core Team <team@pagizer.org>
 * @package     pagizer
 * @subpackage  website
 */

class m_website_actions_block_BlockDeleteAction extends m_backoffice_extends_Action
{
	public function execute()
	{
		$blockId = $this->getRequestParameter("blockId");
		$docId = $this->getRequestParameter("docId");
		$docLang = strtolower($this->getRequestParameter("docLang"));
		
		$tempDocService = m_backoffice_services_TempDocService::getInstance();
		
		if($tempDocService->hasTemporary($docId, $docLang))
		{
			$page = $tempDocService->getTemporaryDocument($docId, $docLang);
		}
		else
		{
			$page = f_document_Provider::getInstance()->getByModelAndUniqueId('website/Page', $docId, $docLang);			
		}
		
		$block = $page->getBlockById($blockId);
		
		$this->addToModel("page", $page);		
		$this->addToModel("block", $block);		
		$this->setView('success');
	}	
	
	public function validate()
	{
		return $this->getUserContext()->hasRight(array("backoffice_accessBo", "website_TabPageStructure"));
	}
}